package com.lenovo.framework.ui;

import android.os.Handler;
import android.os.Looper;
import android.os.Message;

import java.lang.ref.WeakReference;

/**
 * Created by hejie5 on 2016/3/21.
 */
public class UIWeakRefHandler<T> extends Handler{
    private final WeakReference<T> weakReference;
    public UIWeakRefHandler(T obj) {
        super(Looper.getMainLooper());
        weakReference = new WeakReference<T>(obj);
    }
    /**
     * Handle system messages here when ui is avaliable.
     */
    public void dispatchMessage(Message msg) {
        T service = weakReference.get();
        if (service != null) {
            super.dispatchMessage(msg);
        }
    }
}
